package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.mapper.NursingProjectMapper;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getAllNursingProject(String name, Integer page, Integer pageSize, Integer status) {
        PageHelper.startPage(page, pageSize);
        Page<NursingProjectVo> byPage = nursingProjectMapper.findByPage(name,status);
        System.out.println(byPage);
        return PageResponse.of(byPage, NursingProjectVo.class);
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProjectMapper.insert(nursingProject);

    }

    @Override
    public NursingProjectVo selectById(Integer id) {
        return nursingProjectMapper.selectById(id);
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        nursingProjectMapper.update(nursingProjectDto);
    }

    @Override
    public void enableOrDisable(Integer id, Integer status) {
        nursingProjectMapper.enableOrDisable(id, status);
    }

    @Override
    public void deleteNursingProject(Integer id) {
        nursingProjectMapper.delete(id);
    }

//    @Override
//    public List<NursingProjectVo> getAll() {
//        List<NursingProjectVo> list = nursingProjectMapper.getAll();
//        return list;
//    }
}
